<style>
    .forx {
        display: none;
    }
</style>
{{$privilege:=.privilege}}
<div class="panel panel-default">
    <div class="panel-body">
        <form class="form-horizontal ajaxform" ajaxSuccess="success" ajaxAlways="always" method="post" action="/privilege/{{.action}}">
            <input type="hidden" name="privilege_id" value="{{$privilege.privilege_id}}">
            <div class="form-group">
                <label class="col-sm-2 control-label"><span class="text-danger"> * </span>权限名称</label>
                <div class="col-sm-4">
                    <input type="text" name="name" class="form-control" value="{{$privilege.name}}">
                </div>
                <div class="col-md-4">
                    <span class="text-danger"> * 请将汉字限制在15个以内</span>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label"><span class="text-danger"> * </span>类型</label>
                <div class="col-sm-4">
                    <label class="radio-inline">
                    <input type="radio" name="type" value="navigator">
                    导航
                </label>
                    <label class="radio-inline">
                    <input type="radio" name="type" value="menu">
                    菜单
                </label>
                    <label class="radio-inline">
                    <input type="radio" name="type" value="controller">
                    控制器
                </label>
                </div>
            </div>
            <div class="form-group forx for-menu">
                <label class="col-sm-2 control-label"><span class="text-danger"> * </span>上级导航</label>
                <div class="col-sm-4">
                    <select name="parent_n" class="form-control" default="{{$privilege.parent_id}}">
                    {{range .navigators}}
                    <option value="{{.privilege_id}}">{{.name}}</option>
                    {{end}}
                </select>
                </div>
                <div class="col-md-4">
                    <span class="text-danger"></span>
                </div>
            </div>
            <div class="form-group forx for-controller">
                <label class="col-sm-2 control-label"><span class="text-danger"> * </span>上级菜单</label>
                <div class="col-sm-4">
                    <select name="parent_m" class="form-control" default="{{$privilege.parent_id}}">
                    {{range .menus}}
                    <option value="{{.privilege_id}}">{{.parent}} -> {{.name}}</option>
                    {{end}}
                </select>
                </div>
                <div class="col-md-4">
                    <span class="text-danger"></span>
                </div>
            </div>
            <div class="form-group forx for-controller">
                <label class="col-sm-2 control-label"><span class="text-danger"> * </span>控制器名称</label>
                <div class="col-sm-4">
                    <input type="text" name="controller" class="form-control" value="{{$privilege.controller}}">
                </div>
                <div class="col-md-4">
                    <span class="text-danger"></span>
                </div>
            </div>
            <div class="form-group forx for-controller">
                <label class="col-sm-2 control-label"><span class="text-danger"> * </span>方法名称</label>
                <div class="col-sm-4">
                    <input type="text" name="action" class="form-control" value="{{$privilege.action}}">
                </div>
                <div class="col-md-4">
                    <span class="text-danger"></span>
                </div>
            </div>
            <div class="form-group forx for-controller">
                <label class="col-sm-2 control-label"><span class="text-danger"> * </span>目标地址</label>
                <div class="col-sm-4">
                    <input type="text" name="target" class="form-control" value="{{$privilege.target}}">
                </div>
                <div class="col-md-4">
                    <span class="text-danger"></span>
                </div>
            </div>
            <div class="form-group forx for-controller">
                <label class="col-sm-2 control-label"><span class="text-danger"> * </span>菜单项</label>
                <div class="col-sm-4">
                    <label class="radio-inline">
                    <input type="radio" name="is_display" value="1">
                    是
                </label>
                    <label class="radio-inline">
                    <input type="radio" name="is_display" value="0">
                    否
                </label>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label"><span class="text-danger"> * </span>排序数字</label>
                <div class="col-sm-2">
                    <input type="text" name="sequence" class="form-control" value="{{$privilege.sequence}}">
                </div>
                <div class="col-md-4">
                    <span class="text-danger"> * 数字小的在前面</span>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label"><span class="text-danger"> * </span>图标</label>
                <div class="col-sm-4">
                    <input name="icon" class="icon-placeholder icon" type="hidden" value="{{$privilege.icon}}" />
                    <a class="btn btn-md btn-default icon-selector">
                        <span class="icon  icon-placeholder-preview">
                        <i class="{{$privilege.icon}}"></i>
                    </span> &nbsp;&nbsp;选择图标...
                    </a>
                </div>
                <div class="col-md-4">

                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-10">
                    <button type="submit" class="btn btn-success">保存</button>
                </div>
            </div>
        </form>
    </div>
</div>
<script>
    $('[name="type"]').click(function() {
        $(".forx").hide();
        $('.for-' + this.value).show();
    });
    $('[name="type"]').each(function() {
        if (this.value == '{{$privilege.type}}') {
            $(this).attr('checked', true).trigger('click');
        }
    });
    $('[name="is_display"]').each(function() {
        if (this.value == '{{$privilege.is_display}}') {
            $(this).attr('checked', true).trigger('click');
        }
    })
</script>